<template>
  <div>
    <TheCreateForm
      ref="formRefs"
      title="新增退款"
      :options="formOptions"
      :form.sync="form"
      :autoClose="false"
      tip="提交后不可修改，请确认信息无误"
      @submit="handleRefund"
    ></TheCreateForm>
    <el-dialog title="钉钉授权" :visible.sync="dialogVisible" width="340px">
      <div id="self_defined_element_refund" class="self-defined-classname"></div>
    </el-dialog>
  </div>
</template>

<script>
import { apiMerchantPage } from "@/api/storeManager.js";
import { getAccessToken } from "@/utils/dingTalk.js";
export default {
  components: {},
  data() {
    return {
      dialogVisible: false,
      form: {},
      formOptions: [
        {
          type: "select",
          field: "dataId",
          title: "退款商家",
          default: "",
          api: apiMerchantPage,
          params: { pageNum: 1, pageSize: -1 },
          optionKey: "merchantContactName",
          optionValue: "merchantId",
          placeholder: "请选择...",
          options: [],
          rules: [
            { required: true, message: "请选择合作商家", trigger: "change" },
          ],
        },

        {
          type: "input-number",
          field: "changeAmount",
          title: "退款金额",
          default: "",
          placeholder: "请输入...",
          precision: 0,
          controls: false,
          max: 999999,
          min: 100,
          rules: [
            { required: true, message: "请输入充值金额...", trigger: "blur" },
            {
              type: "number",
              max: 999999,
              min: 100,
              message: "请输入100-999999范围内整数...",
              trigger: "change",
            },
          ],
        },
        {
          type: "select",
          field: "payMethod",
          title: "退款渠道",
          default: "",
          placeholder: "请选择...",
          options: [
            { label: "支付宝", value: "ALIPAY" },
            { label: "微信", value: "WECHAT" },
            { label: "银行卡", value: "BANK" },
            { label: "其他", value: "OTHER" },
          ],
          rules: [{ required: true, message: "请选择...", trigger: "change" }],
        },
        {
          type: "upload",
          field: "approvalCertificate",
          title: "转账凭证",
          default: [],
          maxlength: 6,
          rules: [
            { required: true, message: "请上传转账凭证...", trigger: "change" },
          ],
        },
        {
          type: "textarea",
          field: "approvalRemark",
          title: "备注",
          default: "",
          maxlength: 40,
          placeholder: "备注...",
        },
      ],
    };
  },
  mounted() {},
  methods: {
    open() {
      this.$refs.formRefs.open();
    },
    handleRefund(values) {
      this.dialogVisible = true;
      const forms = { ...values };
      this.$nextTick(() => {
        getAccessToken({
          domId:'self_defined_element_refund',
          cb: (res) => {
            if (res.type == "success") {
              console.log(res, "aaaaaasss");
              this.$emit("submit", { values: forms, authCode: res.authCode });
              this.dialogVisible = false;
              this.$refs.formRefs.close();
            } else {
              this.dialogVisible = false;
            }
          },
        });
      });
    },
  },
};
</script>

